<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>后台管理</title>
    <!-- Bootstrap core CSS -->
    <link th:href="@{/webjars/bootstrap/4.4.1-1/css/bootstrap.css}" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link th:href="@{/asserts/css/dashboard.css}" rel="stylesheet">
    <link href="iconfont/iconfont.css" th:href="@{/iconfont/iconfont.css}" rel="stylesheet">
    <link href="asserts/css/from-table.css" th:href="@{/asserts/css/from-table.css}" rel="stylesheet">

    <style type="text/css">
        /* Chart.js */

        @-webkit-keyframes chartjs-render-animation {
            from {
                opacity: 0.99
            }
            to {
                opacity: 1
            }
        }

        @keyframes chartjs-render-animation {
            from {
                opacity: 0.99
            }
            to {
                opacity: 1
            }
        }

        .info {
            float: left;
        }

        .pagination {
            float: right;
        }

    </style>
</head>

<body>
<!--引入抽取的topbar-->
<!--模板名：会使用thymeleaf的前后缀配置规则进行解析-->
<div th:replace="commons/bar::topbar"></div>

<div class="container-fluid">
    <div class="row">
        <!--引入侧边栏-->
        <div th:replace="commons/bar::#sidebar(activeUri='emps')"></div>

        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
            <form class="navbar-form search-range" th:action="@{/search}" >
                <div class="input-group mb-3">
                    <input name="name" type="text" class="form-control info-box" placeholder="名字" th:value="${name}">
                    <input name="workID" type="text" class="form-control info-box" placeholder="工号:ce10****" th:value="${workID}">
                    <select class="form-control info-box" name="deptname">
                        <option value="">--请选择--</option>
                        <option th:selected="${deptname} eq '行政部'" >行政部</option>
                        <option th:selected="${deptname} eq '财务部'" >财务部</option>
                        <option th:selected="${deptname} eq '质量管理部'" >质量管理部</option>
                        <option th:selected="${deptname} eq '营销部'" >营销部</option>
                        <option th:selected="${deptname} eq '运营部'" >运营部</option>
                        <option th:selected="${deptname} eq '研发部'" >研发部</option>
                        <option th:selected="${deptname} eq '运维部'" >运维部</option>
                        <option th:selected="${deptname} eq '人事部'" >人事部</option>
                        <!--<option th:selected="${deptname}" th:each="department:${depts}"  th:text="${department.name}"></option>-->
                    </select>
<!--                    <input name="workDate" type="text" class="form-control info-box" placeholder="1970-01-01" th:value="${workDate}">-->
                    <div class="datebox">
                        <input type="text" name="workDate" id="date" class="date" th:value="${workDate}" placeholder="1970-01-01" />
                        <input type="date" class="mydate" onchange="ds(this)"/>
                    </div>
                    <div class="input-group-append">
                        <button class="btn btn-success query" type="submit">
                            <span class="iconfont icon--search1"></span>
                        </button>
                    </div>
                </div>
            </form>

            <table class="layui-hide" id="employee" lay-filter="employeeTable"></table>
            <h2 class="add"><a class="btn btn-sm btn-success"  th:href="@{/emp}">添加</a></h2>

            <div class="table-responsive">
                <table class="table table-striped table-sm table-bordered" id="mytable">
                    <thead>
                    <tr>
                        <th>编号</th>
                        <th>员工工号</th>
                        <th>姓名</th>
                        <th>性别</th>
                        <th>入职时间</th>
                        <th>联系号码</th>
                        <th>部门</th>
                        <th>职位</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="emp:${pageInfo.list}">
                        <!--<td th:text="${empStat.index+1}"></td>-->
                        <td>[[${emp.EId}]]</td>
                        <td>[[${emp.workID}]]</td>
                        <td>[[${emp.name}]]</td>
                        <td>[[${emp.gender}]]</td>
                        <td>[[${#dates.format(emp.workDate, 'yyyy-MM-dd')}]]</td>
                        <td>[[${emp.phone}]]</td>
                        <td>[[${emp.dept.name}]]</td>
                        <td>[[${emp.position.name}]]</td>
                        <td>[[${emp.workState}]]</td>
                        <td>
                            <a class="btn btn-sm btn-primary" th:href="@{/emp/}+${emp.EId}">编辑</a>
                            <button th:id="${emp.EId}" th:name="${emp.name}" th:attr="del_uri=@{/emp/}+${emp.EId}"
                                    class="btn btn-sm btn-danger deleteBtn">删除
                            </button>
                        </td>
                    </tr>
                    </tbody>
                </table >

                <div class="msg">
                    <p th:text="${info}" th:if="${not #strings.isEmpty(info)}"></p>
                </div>

                <ul class="pagination" th:if="${name}!=null">
                    <li class="page-item"><a  class="page-link" th:if="${pageInfo.hasPreviousPage}"  th:href="@{${url}(pageNum=${pageInfo.navigateFirstPage},name=${name},workID=${workID},deptname=${deptname},workDate=${workDate})}">首页</a></li>
                    <li class="page-item"><a  class="page-link" th:if="${pageInfo.hasPreviousPage}"  th:href="@{${url}(pageNum=${pageInfo.prePage},name=${name},workID=${workID},deptname=${deptname},workDate=${workDate})}">上一页</a></li>
                    <li class="page-item"><a  class="page-link" th:if="${pageInfo.hasNextPage}"  th:href="@{${url}(pageNum=${pageInfo.nextPage},name=${name},workID=${workID},deptname=${deptname},workDate=${workDate})}">下一页</a></li>
                    <li class="page-item"><a  class="page-link" th:if="${pageInfo.hasNextPage}"      th:href="@{${url}(pageNum=${pageInfo.navigateLastPage},name=${name},workID=${workID},deptname=${deptname},workDate=${workDate})}">末页</a></li>
                </ul>
                <ul class="pagination" th:if="${name}==null">
                    <li class="page-item"><a class="page-link" th:href="@{/emps}">首页</a></li>
                    <li class="page-item"><a class="page-link"
                                             th:href="@{${url}(pageNum=${pageInfo.hasPreviousPage}?${pageInfo.prePage}:1)}">上一页</a>
                    </li>
                    <li class="page-item"><a class="page-link"
                                             th:href="@{${url}(pageNum=${pageInfo.hasNextPage}?${pageInfo.nextPage}:${pageInfo.pages})}">下一页</a>
                    </li>
                    <li class="page-item"><a class="page-link" th:href="@{${url}(pageNum=${pageInfo.pages})}">尾页</a>
                    </li>
                </ul>

                <p class="info">
                    当前第 <span th:text="${pageInfo.pageNum}"></span> 页,总共 <span
                        th:text="${pageInfo.pages}"></span> 页,共 <span
                        th:text="${pageInfo.total}"></span> 条记录
                </p>

                <!--th:if="${pageInfo.hasPreviousPage}"
                    th:if="${pageInfo.hasPreviousPage}"
                    th:if="${pageInfo.hasNextPage}"
                    th:if="${pageInfo.hasNextPage}"    -->
            </div>
        </main>
        <form id="deleteEmpForm" method="post">
            <input type="hidden" name="_method" value="delete"/>
        </form>
    </div>
</div>

<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script type="text/javascript" th:src="@{/webjars/jquery/3.5.0/jquery.js}"></script>
<!--<script type="text/javascript" th:src="@{/webjars/popper.js/1.14.3/popper.js}"></script>-->
<!--<script type="text/javascript" th:src="@{/webjars/bootstrap/4.4.1-1/js/bootstrap.js}"></script>-->

<script type="text/javascript">
    function ds(obj){
        document.getElementById('date').value = obj.value;
    }

    $(".deleteBtn").click(function () {

        var wid = $(this).attr("id");
        console.log(wid);
        var ename = $(this).attr("name");
        console.log(ename);

        //删除当前员工的
        if (confirm("确定要删除工号为" + wid + "，姓名为" + ename + "的所有数据吗?")) {
            $("#deleteEmpForm").attr("action", $(this).attr("del_uri")).submit();
            return true;
        } else {
            return false;
        }

    });
</script>
</body>
</html>